from django.db import models

# 在setting.py中找已注册的apps: api.apps.ApiConfig
class Device(models.Model):
    """设备表"""

    dy_account = models.CharField(verbose_name="抖音账号", max_length=64)
    phone_model = models.CharField(verbose_name="手机型号", max_length=64)
    did = models.CharField(verbose_name="设备ID", max_length=32)

    class Meta:
        verbose_name_plural = "设备表"

    def __str__(self):
        return f"{self.did}-{self.dy_account}"

class Task(models.Model):
    """任务表"""

    # device_id = models.IntegerField(verbose_name="设备ID") # 这样写没有约束
    # 以下,在数据库真正生成的是 device_id
    device = models.ForeignKey(verbose_name="关联设备", to="Device",
                               on_delete=models.CASCADE)  # to="Device" ---> 默认关联主键 Device.id    CASCADE--->级联删除


    address = models.TextField(verbose_name="直播间地址", help_text="手机中分享获得指定直播间地址")  #Text
    text = models.TextField(verbose_name="评论内容", help_text="回车换行，程序会自动读取每行进行评论")
    loop_count = models.IntegerField(verbose_name="循环次数", default=1) # int

    #       0       1    2
    # 状态：待执行/正在执行/已完成
    status = models.IntegerField(verbose_name="状态", default=0, choices=[(0, "待执行"), (1, "正在执行"), (2, "已完成"), ])

    class Meta:
        verbose_name_plural = "任务表"




























